from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.edge.options import Options as EdgeOptions
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

# 创建 Edge 选项
edge_options = EdgeOptions()
# edge_options.add_argument('--headless')  # 可选：无头模式
# 手动指定 msedgedriver 路径（❗非常重要）
service = EdgeService(executable_path=r'C:\Users\admin\Downloads\edgedriver_win64\msedgedriver.exe')
# 启动 Edge 浏览器
driver = webdriver.Edge(service=service, options=edge_options)
driver.maximize_window()
# 打开网页
url = "https://vsoc.bjev.com.cn/user/login"
print(f"正在打开: {url}")
driver.get(url)
# 等待几秒查看页面是否加载成功
wait = WebDriverWait(driver, 20)  # 等待最多 20 秒
# 输出当前页面标题
print("当前页面标题:", driver.title)
'''--------------------登录-----------------------------------------'''
driver.find_element(By.CSS_SELECTOR, "#username").send_keys("yangbiao")
driver.find_element(By.CSS_SELECTOR, "#password").send_keys("3738g2$@4Pq")
driver.find_element(By.CSS_SELECTOR, "#root > div > div.login___vRELY > div.form___qrIjX > div > form > button").click()
time.sleep(15)# 我弄验证码
'''VSOC-安全态势'''
# VSOC
driver.find_element(By.CSS_SELECTOR, "#root > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(2)").click()
time.sleep(1)
# 安全态势
submenu_icon = wait.until(EC.element_to_be_clickable((By.XPATH, '//ul[contains(@id, "/vsoc-popup")]/li[1]/div/i')))

# 再点击图标
submenu_icon.click()

# 安全态势->总体态势
driver.find_element(By.XPATH,"//li[@title='总体态势']").click()
time.sleep(3)
# 安全态势->总体态势
driver.find_element(By.XPATH,"//li[@title='品牌态势']").click()
time.sleep(3)
# 安全态势->总体态势
driver.find_element(By.XPATH,"//li[@title='车型态势']").click()
time.sleep(3)
# 安全态势->总体态势
driver.find_element(By.XPATH,"//li[@title='漏洞态势']").click()
time.sleep(3)
# 安全态势->风险态势
driver.find_element(By.XPATH,"//li[@title='风险态势']").click()
time.sleep(5)










#关闭浏览器
driver.quit()